<?php

require_once  __DIR__ . '/includes/authenticate.php';

include __DIR__ . '/mainpage.php';

?>

<div id="container-fluid">
	<div id="row">
		<div class="col-lg-4 col-md-4 col-sm-8 col-xs-8"  style="margin:0 auto; float:none;">
		<h3> Add Action Tag </h3>

		<form method="post">
			
			  	<div class="form-group">
              
                  	<label>Youtube Video ID:</label>              
                  	<input type="text" name="embed_code" id="embed_code" class="form-control" placeholder="Youtube Video ID" />
              	</div>

              	<div class="form-group">
              
                  	<label>Title:</label>              
                  	<input type="text" name="title" id="title" class="form-control" placeholder="Title for your video" />
              	</div>


                <div class="form-group">
              
                    <label>Comment:</label>              
                    <textarea name="comment" id="comment" class="form-control" placeholder="Comment to show with this video"></textarea>
                </div>

              <button class="btn btn-success btn-block submit">Submit</button>
		</form>
		<br>
		<span id="success_message"></span>
		</div>
	</div>
</div>

<script type="text/javascript">
	
$(".submit").on("click", function(e) {
		postData = $(this.form).serialize();
		$.ajax({
 			type: "POST",
  			url: "./includes/handlers/video_add_handler.php",
  			data: postData,
  			success: function(data) {
 				$("#success_message").html(data);		
        $("#comment").val('');
        $("#embed_code").val('');
        $("#title").val('');
  			},
  			error: function (xhr, status, error) {
  				alert(xhr.responseText);
  			}
  		}); 
		e.preventDefault();		
});

</script>
